home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions OjasFull component
-
- #include "NSDLL.h"
-
- /*************************************************************/
- /* Macros to access the PE layers and weights in matrix form */
-
- #define in(i,j) input[j+i*inCols]
- #define out(i,j) output[j+i*outCols]
- #define W(i,j) weights[j+i*inCount]
-
- /******************************/
- /* Unsupervised weight update */
-
- __declspec(dllexport) void performUnsupervised(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *input, // Pointer to input layer
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- NSFloat *output, // Pointer to the output layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols, // Number of columns of PEs in the output layer
- NSFloat *weights, // Pointer to fully connected weight matrix
- NSFloat step // Learning rate
- )
- {
- int i, j,
- inCount=inRows*inCols,
- outCount=outRows*outCols;
- NSFloat partialSum;
-
- for (j=0; j<inCount; j++) {
- partialSum = (NSFloat)0;
- for (i=0; i<outCount; i++)
- partialSum += output[i] * W(i,j);
- for (i=0; i<outCount; i++)
- W(i,j) += step*output[i]*(input[j] - partialSum);
- }
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocUnsupervised(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols // Number of columns of PEs in the output layer
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeUnsupervised(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */